package com.wh.music.controller;

import com.wh.music.Util.ResultCode;
import com.wh.music.Util.ResultEntity;
import com.wh.music.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/admin")
public class AdminController {


  @Autowired
  private AdminService adminService;

  /**
   * 判断是否登录成功
   */
  @PostMapping("/login")
  public ResultEntity<String> loginStatus(@RequestParam("name") String name,
                                          @RequestParam("password") String password,
                                          HttpServletRequest request){
    boolean flag = adminService.verifyPassword(name,password);
    if(flag){
      request.getSession().setAttribute("user", name);
      return new ResultEntity<String>(ResultCode.SUCCESS, name);
    }else {
      return new ResultEntity<String>(ResultCode.USER_NOT_EXIST, null);
    }
  }
}
